package com.hjms.account.services;

import cn.hutool.core.date.DateUtil;
import com.hjms.account.contracts.IAccountService;
import com.hjms.account.contracts.dto.account.AddAccountDto;
import com.hjms.account.contracts.vo.account.AccountVo;
import com.hjms.account.domain.Account;
import com.hjms.account.repository.AccountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.UUID;

/**
 * @author 何杨谊
 * @description: TODO
 * @date 2022/12/30 17:28
 */
@Service
public class AccountService implements IAccountService {
    @Resource
    private AccountMapper accountMapper;

    @Override
    public String Add(AddAccountDto dto) {
        Account entity=new Account();
        entity.setId(UUID.randomUUID().toString());
        entity.setNickName(dto.getNickName());
        entity.setEmail(dto.getEmail());
        entity.setCreateTime(new Timestamp(DateUtil.current()));
        entity.setPhone(dto.getPhone());
        accountMapper.insert(entity);
        return  entity.getId();
    }

    @Override
    public AccountVo Get(String accountId) {
        Account entity = accountMapper.selectById(accountId);
        AccountVo vo=new AccountVo();
        vo.setEmail(entity.getEmail());
        vo.setId(entity.getId());
        vo.setPhone(entity.getPhone());
        vo.setNickName(entity.getNickName());
        return vo;
    }
}
